package util

import (
	"log"

	"github.com/casbin/casbin/v2"
)

var Enforcer *casbin.Enforcer

// CasbinInit 初始化 Casbin
func CasbinInit() (err error) {
	// 加载模型和策略文件
	Enforcer, err = casbin.NewEnforcer("config/model.conf", "config/policy.csv")
	if err != nil {
		log.Fatalf("Failed to load Casbin enforcer: %v", err)
		return err
	}

	// 打印所有策略
	policies, _ := Enforcer.GetPolicy()
	for _, policy := range policies {
		log.Printf("Policy: %v", policy)
	}
	return nil
}
